FILE(GLOB FLTK_ALL_SRC "*.[fF][lL]")

SET(FLTK_CPP_SRC "")

FOREACH(FLTK_SRC ${FLTK_ALL_SRC})
    # generate fltk output source file name
    GET_FILENAME_COMPONENT(T_BASENAME ${FLTK_SRC} NAME_WE)
    SET(T_OUT_CPPNAME ${T_BASENAME}.cpp)
    SET(T_OUT_HPPNAME ${T_BASENAME}.hpp)

    SET(FLTK_CPP_SRC
        ${FLTK_CPP_SRC}
        ${CMAKE_CURRENT_BINARY_DIR}/${T_OUT_HPPNAME}
        ${CMAKE_CURRENT_BINARY_DIR}/${T_OUT_CPPNAME})

    ADD_CUSTOM_COMMAND(OUTPUT ${T_OUT_HPPNAME} ${T_OUT_CPPNAME}
        DEPENDS ${FLTK_SRC}
        COMMAND fluid -c -o ${T_OUT_CPPNAME} -h ${T_OUT_HPPNAME} ${FLTK_SRC}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        )
ENDFOREACH()

AUX_SOURCE_DIRECTORY(. MONOSERVER_SRC)
ADD_EXECUTABLE(monoserver ${MONOSERVER_SRC} ${FLTK_CPP_SRC})
ADD_DEPENDENCIES(monoserver mir2x_3rds)

TARGET_INCLUDE_DIRECTORIES(monoserver PRIVATE ${MIR2X_COMMON_SOURCE_DIR})
TARGET_INCLUDE_DIRECTORIES(monoserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
TARGET_INCLUDE_DIRECTORIES(monoserver PRIVATE ${CMAKE_CURRENT_LIST_DIR})

TARGET_LINK_LIBRARIES(monoserver common                )
TARGET_LINK_LIBRARIES(monoserver ${LUA_LIBRARIES}      )
TARGET_LINK_LIBRARIES(monoserver ${FLTK_LIBRARIES}     )
TARGET_LINK_LIBRARIES(monoserver sqlite3               )
TARGET_LINK_LIBRARIES(monoserver ${SQLITECPP_LIBRARIES})
TARGET_LINK_LIBRARIES(monoserver ${CMAKE_DL_LIBS}      )
TARGET_LINK_LIBRARIES(monoserver ${G3LOG_LIBRARIES}    )
TARGET_LINK_LIBRARIES(monoserver ${LZ4_LIBRARIES}      )
TARGET_LINK_LIBRARIES(monoserver ${ZSTD_LIBRARIES}     )
TARGET_LINK_LIBRARIES(monoserver Threads::Threads      )

IF(WIN32 AND MSVC)
    MESSAGE(STATUS "Use windows native fiber library")
ELSE()
    TARGET_LINK_LIBRARIES(monoserver ${ACO_LIBRARIES})
ENDIF()

INSTALL(TARGETS monoserver DESTINATION server)
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/server/script DESTINATION server)
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/client/bin/res/map DESTINATION server)
